package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @Author: 孙润达
 * @Date: 2022/1/9 14:27
 * 页面详情
 */
@Controller
public class ItemController {
     /*
     * https://item.jd.com/100031030588.html
     *                     skuId
     * */
     @Autowired
     private ItemFeignClient itemFeignClient;
     @GetMapping("/{skuId}.html")
    public String itemHtml(@PathVariable Long skuId, Model model){
//    public String itemHtml(@PathVariable Long skuId, Model model, Map map){
         Map item = itemFeignClient.getItem(skuId);
         /*
         * 查询的结果为map集合，所以放到model里要用addAllAttributes
         * map里里要用putAll
         * */
         model.addAllAttributes(item);
//         map.putAll(item);
         return "item/index";
     }

}
